home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / oogl / util / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  2.3 KB  |  100 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include <stdarg.h>
  13. #include "ooglutil.h"
  14.  
  15.  
  16. char    *_GFILE;    /* Name of file where error is found */
  17. int    _GLINE;        /* Line number in file where error is found */
  18. int    OOGL_Errorcode;    /* Unique integer error code */
  19.  
  20. int _OOGLError(int errorcode,char* fmt,...)
  21. {
  22.    va_list args;
  23.    va_start(args, fmt);
  24.    if(errorcode & OE_VERBOSE)
  25.     fprintf(stderr, "Error <%d>: ",errorcode);
  26.    if (fmt != NULL) vfprintf(stderr, fmt, args);
  27.    fprintf(stderr, "\n");
  28.    if(errorcode & OE_VERBOSE)
  29.     fprintf(stderr, "File: %s, Line: %d\n\n",_GFILE,_GLINE);
  30.    OOGL_Errorcode = errorcode;
  31.    va_end(args);
  32.    return 0;
  33. }
  34.  
  35. /*
  36.  * Report syntax error
  37.  */
  38. void OOGLSyntax(FILE *f, char *fmt, ...)
  39. {
  40.    static FILE *oldf;
  41.    static FILE oldfile;
  42.    static char oldtext[20];
  43.    char *context;
  44.  
  45.    va_list args;
  46.    va_start(args, fmt);
  47.    vfprintf(stderr, fmt, args);
  48.    if(f == oldf && bcmp(f, &oldfile, sizeof(FILE)) == 0 &&
  49.      (f->_base == NULL || bcmp(f->_base, oldtext, sizeof(oldtext)) == 0)) {
  50.     fprintf(stderr, " [ditto]\n");
  51.    } else {
  52.     context = fcontext(f);
  53.     fprintf(stderr,
  54.         context[0] != '\0' ? ":\n%s" : " [no text available]\n",
  55.         context);
  56.     oldf = f;
  57.     oldfile = *f;
  58.     if(f->_base) memcpy(oldtext, f->_base, sizeof(oldtext));
  59.    }
  60.    va_end(args);
  61. }
  62.  
  63. void GeomWarn(char *fmt, ...)
  64. {
  65.   int level = 2;
  66.   va_list args;
  67.   
  68.   if(fmt[0] < ' ' && fmt[0] != '\0')
  69.     level = *fmt++;
  70.   /* Maybe we have a current warning level below which we don't print */
  71.  
  72.   va_start (args, fmt);
  73.   
  74.   vfprintf (stderr, fmt, args);
  75.   fputc('\n', stderr);
  76.   fflush(stderr);
  77.   va_end (args);
  78. }
  79.  
  80. char *
  81. sperrno(unsigned int err)
  82. {
  83.   extern unsigned int sys_nerr;
  84.   extern char *sys_errlist[];
  85.   static char errstr[16];
  86.   
  87.   if(err < sys_nerr)
  88.     return(sys_errlist[err]);
  89.   sprintf(errstr, "Error %d", err & 0xffff);
  90.   return(errstr);
  91. }
  92.  
  93. char *
  94. sperror(void)
  95. {
  96.     extern int errno;
  97.  
  98.     return sperrno(errno);
  99. }
  100.